using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using FreeFlow.Client;

namespace FreeFlow.WinFormsControls
{
	/// <summary>
	/// Control for handling attachments.
	/// </summary>
	public class AttachmentControl : UserControl, IFillable
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

    /// <summary>
    /// Creates a new <see cref="AttachmentControl"/> instance.
    /// </summary>
		public AttachmentControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

      Width = 50;
      Height = 45;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AttachmentControl));
      this.pictureBox1 = new System.Windows.Forms.PictureBox();
      this.panel1 = new System.Windows.Forms.Panel();
      this.panel3 = new System.Windows.Forms.Panel();
      this.panel2 = new System.Windows.Forms.Panel();
      this.captionLabel = new System.Windows.Forms.Label();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
      this.panel1.SuspendLayout();
      this.panel3.SuspendLayout();
      this.panel2.SuspendLayout();
      this.SuspendLayout();
      // 
      // pictureBox1
      // 
      this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
      this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
      this.pictureBox1.Location = new System.Drawing.Point(0, 0);
      this.pictureBox1.Name = "pictureBox1";
      this.pictureBox1.Size = new System.Drawing.Size(342, 238);
      this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBox1.TabIndex = 0;
      this.pictureBox1.TabStop = false;
      // 
      // panel1
      // 
      this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
      this.panel1.Controls.Add(this.panel3);
      this.panel1.Controls.Add(this.panel2);
      this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
      this.panel1.Location = new System.Drawing.Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(344, 256);
      this.panel1.TabIndex = 1;
      // 
      // panel3
      // 
      this.panel3.Controls.Add(this.pictureBox1);
      this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
      this.panel3.Location = new System.Drawing.Point(0, 0);
      this.panel3.Name = "panel3";
      this.panel3.Size = new System.Drawing.Size(342, 238);
      this.panel3.TabIndex = 2;
      // 
      // panel2
      // 
      this.panel2.Controls.Add(this.captionLabel);
      this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
      this.panel2.Location = new System.Drawing.Point(0, 238);
      this.panel2.Name = "panel2";
      this.panel2.Size = new System.Drawing.Size(342, 16);
      this.panel2.TabIndex = 1;
      // 
      // captionLabel
      // 
      this.captionLabel.Dock = System.Windows.Forms.DockStyle.Fill;
      this.captionLabel.Location = new System.Drawing.Point(0, 0);
      this.captionLabel.Name = "captionLabel";
      this.captionLabel.Size = new System.Drawing.Size(342, 16);
      this.captionLabel.TabIndex = 0;
      this.captionLabel.Text = "captionLabel";
      this.captionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
      // 
      // AttachmentControl
      // 
      this.Controls.Add(this.panel1);
      this.Name = "AttachmentControl";
      this.Size = new System.Drawing.Size(344, 256);
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
      this.panel1.ResumeLayout(false);
      this.panel3.ResumeLayout(false);
      this.panel2.ResumeLayout(false);
      this.ResumeLayout(false);

    }
		#endregion

    private System.Windows.Forms.PictureBox pictureBox1;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Panel panel2;
    private System.Windows.Forms.Panel panel3;
    private System.Windows.Forms.Label captionLabel;

    private bool readOnly;
    /// <summary>
    /// Gets or sets a value indicating whether the attachment control is read only.
    /// </summary>
    /// <value>
    /// 	<c>true</c> if read only; otherwise, <c>false</c>.
    /// </value>
    public bool ReadOnly
    {
      get
      {
        return readOnly;
      }
      set
      {
        readOnly = value;
      }
    }
    #region IFillable Members

    /// <summary>
    /// Renders the control with static layout information using the specified field.
    /// </summary>
    /// <param name="field">Field.</param>
    public void Render(FreeFlow.Client.Field field)
    {
      captionLabel.Text = (field as AttachmentField).Caption;
      using (Graphics g = captionLabel.CreateGraphics())
      {
        SizeF size = g.MeasureString(captionLabel.Text, captionLabel.Font);
        Width = (int)size.Width + 5;
      }
    }

    /// <summary>
    /// Fills the control with values from the specified field.
    /// </summary>
    /// <param name="field">Field.</param>
    public void Fill(FreeFlow.Client.Field field)
    {
      // TODO:  Add AttachmentControl.Fill implementation
    }

    /// <summary>
    /// Fills the field from the control.
    /// </summary>
    /// <param name="field">Field.</param>
    public void FillField(Field field)
    {
      // TODO - implement
    }

    #endregion
  }
}
